package logic

import (
	"context"
	"errors"
	"strings"
	"work/model/mysql"

	"work/workrpc/internal/svc"
	"work/workrpc/workrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ContentAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewContentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ContentAddLogic {
	return &ContentAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ContentAddLogic) ContentAdd(in *workrpc.ContentAddRequest) (*workrpc.ContentAddResponse, error) {
	// todo: add your logic here and delete this line
	content := mysql.Content{
		Comment: in.Comment,
		UserId:  in.UserId,
		StoryId: in.StoryId,
	}
	if strings.Contains(in.Comment, "抄袭") || strings.Contains(in.Comment, "摄政") {
		return nil, errors.New("包含敏感词汇")
	}
	err := content.ContentAdd(mysql.DB)
	if err != nil {
		return nil, err
	}
	return &workrpc.ContentAddResponse{
		ContentId: int64(content.ID),
	}, nil
}
